<?php
/**
 * Created by PhpStorm.
 * User: zhanglin02
 * Date: 2016/3/31
 * Time: 17:58
 */

namespace Admin\Model;
use Think\Model;

class AdminModel extends Model
{
    /*protected $_validate=array(
      array('username','/^\w{4,10}','用户名不合法（4-10位，英文、数字、下划线）',1),
      array('password','/^\w{6,12}','用户名不合法（4-10位，英文、数字、下划线）',1),
    );*/
    //判断管理员的用户名密码
    public function checkLogin(){
        $username = $this->data['username'];//表单提交的用户名
        $password = $this->data['password'];//表单提交的密码
        $data = $this->field('password,salt')->where(array('username'=>$username))->find();
        if($data){//判断密码
            return $data['password'] = $this->password($password,$data['salt']);
        }
    }
    public function password($password,$salt){
        return md5(md5($password).$salt);
    }
}